package pin;
/* Hoe te Gebruiken:
 * deBon((String[]) bericht,(String) plaatjelokatie);
 */

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.ImageIcon;

public class deBon {

    private PageFormat mPageFormat;
    public static String[] message = {"Lucky Bank", "uw saldo:" + " \u20AC" + "250"};
    public static String logoImg = "c:/logo.gif";

    public static void main(String[] args){
        new deBon(message,logoImg);
    }

    public deBon(String[] dingen, String imgStr) {
        //Instellingen
        message = dingen;
        logoImg = imgStr;
        //Doen
        PrinterJob pj = PrinterJob.getPrinterJob();
        mPageFormat = new PageFormat();
        Paper paper = new Paper();
        paper.setImageableArea(0, 0, 160, 290);
        paper.setSize(160, 290);
        mPageFormat.setPaper(paper);

        pj.setPrintable(new OutPrintable(), mPageFormat);
        {
            try {
                pj.print();
            } catch (PrinterException e) {
                System.out.println(e);
            }
        }
    }

    public void makeGraphics(Graphics2D g3) {
        g3.setColor(Color.white);
        g3.fillRect(0, 0, 160, 280);
        Image img = new ImageIcon(logoImg).getImage();
        g3.drawImage(img, 25, 15, 36, 36, null);
        g3.setColor(Color.black);
        //Eerste Regel
        g3.setFont(new Font("Monospaced", Font.BOLD, 18));
        g3.drawString(message[0], 25, 70);
        //Volgende Regels
        for(int loopi=1; loopi<message.length; loopi++){
        g3.setFont(new Font("Monospaced", Font.BOLD, 12));
        g3.drawString(message[loopi], 25, 70+(25*loopi));
        }
        //Einde
        g3.drawLine(10, 280, 150, 280);
    }

    class OutPrintable implements Printable {

        public int print(Graphics g, PageFormat pf, int pageIndex) {
            if (pageIndex != 0) {
                return NO_SUCH_PAGE;
            }
            Graphics2D g2 = (Graphics2D) g;
            makeGraphics(g2);
            return PAGE_EXISTS;
        }
    }
}